<template>
  <div class="province-sale-box">
    <div class="select-box">
      <div class="province-box">
        <div class="select1">
          <AreaSelect></AreaSelect>
        </div>
        <DatePicker></DatePicker>
      </div>
    </div>
    <SumSale></SumSale>
    <TabDatas></TabDatas>
  </div>
</template>

<script>
import { getCopartnerdatas, queryprovincialdatas } from "../../api/datas";
import { Bus } from "../../Bus";
import AreaSelect from "../../components/sales/areaSelect";
import DatePicker from "../../components/sales/DatePicker";
import SumSale from "../../components/sales/SumSale";
import TabDatas from "../../components/sales/TabDatas";
export default {
  components: {
    AreaSelect,
    DatePicker,
    SumSale,
    TabDatas,
  },
  data() {
    return {
      province: "",
      timeobj: {
        stime: "",
        etime: "",
      },
      role: 0,
      lists: [
        {
          name: "省",
          prop: "province",
        },
        {
          name: "销量",
          prop: "sale",
        },
      ],
      provinceSales: [],
    };
  },
  mounted() {
    Bus.$on("areadatas", (value) => {
      this.province = value.province;
    });
    Bus.$on("timeobj", (value) => {
      this.timeobj = value;
    });
    Bus.$emit("tab-lists", this.lists);

    Bus.$on("role", (value) => {
      this.role = value;
    });
    this.getAllDatas();
  },
  methods: {
    //获取全部大客户合伙人数据
    getAllDatas() {
      getCopartnerdatas({}).then((res) => {
        let tab_Datas = {};
        if (this.role == 1) {
          tab_Datas = res.partners;
        } else {
          tab_Datas = res.counts;
        }
        Bus.$emit("tab-datas", tab_Datas);
      });
    },

    //查询大客户，合伙人数据
    querydatas() {
      let datas = {};
      let create_time = {};
      datas.province = this.province;
      create_time.startTime= this.timeobj.stime;
      create_time.endTime= this.timeobj.etime;
      queryprovincialdatas({ datas }, { create_time }).then((res) => {
        let tab_Datas = {};
        if (this.role == 1) {
          tab_Datas = res.partners;
        } else {
          tab_Datas = res.counts;
        }
        Bus.$emit("tab-datas", tab_Datas);
      });
    },
  },
  watch: {
    role() {
      if (this.province == "") {
        this.getAllDatas();
      } else {
        this.querydatas();
      }
    },
    province() {
      this.querydatas();
    },
    timeobj(){
      this.querydatas();
    }
  },
};
</script>

<style lang="less" scoped>
.province-sale-box {
  padding-top: 30px;
}
.select-box {
  margin-left: 30px;
  width: inherit;
}
.province-box {
  display: flex;
}
.select1 {
  margin-right: 50px;
  width: 400px;
}
</style>